package com.hr;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Lx1{
    public static void main(String[] args)throws Exception {
        File srcFile = new File("E:\\新建文件夹");
        File destFile = new File("F:\\1\\2");
        copyDir(srcFile,destFile);
    }

    private static void copyDir(File srcFile , File destFile )throws Exception {
        if (srcFile.isFile()) {
            FileInputStream in = null;
            FileOutputStream out = null;

            in = new FileInputStream(srcFile);

            String path = (destFile.getAbsolutePath().endsWith("\\") ? destFile.getAbsolutePath() : destFile.getAbsolutePath() + "\\") + srcFile.getAbsolutePath().substring(3);
            out = new FileOutputStream(path);

            byte[] bytes = new byte[1024 * 1024 * 10];
            int readCount = 0;
            while ((readCount = in.read(bytes)) != -1) {
                out.write(bytes, 0, readCount);
            }
            out.flush();
            if (out != null) {
                out.close();
            }
            return;
        }

        File[] files = srcFile.listFiles();
        for (File file : files){
            if (file.isDirectory()){
                String srcDir = file.getAbsolutePath();
                String destDir = (destFile.getAbsolutePath().endsWith("\\")? destFile.getAbsolutePath() : destFile.getAbsolutePath() + "\\") + srcDir.substring(3);
                File newFile = new File(destDir);
                if (!newFile.exists()){
                    newFile.mkdirs();
                }
            }
            copyDir(file, destFile);
        }
    }
    /*public boolean sendMsg() {
        new File()*/
}



